import api from '../../api/index'
Page({
  data: {
    list: []
  },
  onLoad() {
    this.getwrongList()
  },
  async getwrongList() {
    let {
      wrongList
    } = wx.getStorageSync('wrongList')
    console.log(wrongList);
    // let list = []
    let list = [{
        name: '苹果',
        type: '厨余垃圾',
        check: '可回收物',
      },
      {
        name: '纸巾',
        type: '可回收物',
        check: '有害垃圾'
      },
      {
        name: '指甲',
        type: '其他垃圾',
        check: '有害垃圾'
      },
      {
        name: '纸巾',
        type: '可回收物',
        check: '有害垃圾'
      },
      {
        name: '指甲',
        type: '其他垃圾',
        check: '有害垃圾'
      },
      {
        name: '纸巾',
        type: '可回收物',
        check: '有害垃圾'
      },
      {
        name: '指甲',
        type: '其他垃圾',
        check: '有害垃圾'
      }
    ]
    // await api.getBadproblem().then(res => {
    //     console.log(res.data.rows); 
    //     list = res.data.rows
    // })

    this.setData({
      list
    })
  },

  // ListTouch触摸开始
  ListTouchStart(e) {
    this.setData({
      ListTouchStart: e.touches[0].pageX
    })
  },

  // ListTouch计算方向
  ListTouchMove(e) {
    this.setData({
      ListTouchDirection: e.touches[0].pageX - this.data.ListTouchStart > 0 ? 'right' : 'left'
    })
  },
  // ListTouch计算滚动
  ListTouchEnd(e) {
    if (this.data.ListTouchDirection == 'left') {
      this.setData({
        modalName: e.currentTarget.dataset.target
      })
    } else {
      this.setData({
        modalName: null
      })
    }
    this.setData({
      ListTouchDirection: null
    })
  },
  // 删除
  delWrong(e) {
    let {
      wrong,
      index
    } = e.currentTarget.dataset
    let _this = this
    wx.showModal({
      title: '提示',
      content: '是否确定删除该错题？',
      success(res) {
        if (res.confirm) {
          wx.showLoading({
            title: '加载中..',
          })
          setTimeout(() => {
            wx.hideLoading()
            _this.data.list.splice(index, 1)
            _this.setData({
              list: _this.data.list
            })
          }, 500)
        }
      }
    })
  }
})